mod api;
mod db;
mod model;
mod schema;

use api::*;
use db::init_db_pool;
use dotenv::{dotenv, var};
use salvo::{prelude::*, routing::PathFilter};


#[tokio::main]
async fn main() {
        dotenv().ok();
    init_db_pool(&var("DATABASE_URL").unwrap());

    tracing_subscriber::fmt().init();
    let acceptor = TcpListener::new(format!("0.0.0.0:{}", var("PORT").unwrap())).bind().await;
    let router_api = Router::new()
    .filter(PathFilter::new("api"))
    .get(health);
        let router = Router::with_path("/blurt")
        .push(
            OpenApi::new("api", "0.0.1")
                .merge_router(&router_api)
                .into_router("/api-doc/openapi.json"),
        )
        .push(SwaggerUi::new("/api-doc/openapi.json").into_router("/swagger-ui"))
        .push(router_api)
        .push(Router::with_path("/view/{**}").get(StaticDir::new(["static"]).defaults("index.html").auto_list(true)));
    println!("{:?}", router);
    let service = Service::new(router).hoop(Logger::new());
    Server::new(acceptor).serve(service).await;
}
